#include "USB_HW_Init.h"
#include "stm32f10x.h"
#include "misc.h"
#include "stm32f10x_rcc.h"
#include "usb_lib.h" 
#include "usb_pwr.h"


/*  The number of current device, it is an index to the Device_Table */
/* uint8_t	Device_no; */
/*  Points to the DEVICE_INFO structure of current device */
/*  The purpose of this register is to speed up the execution */
DEVICE_INFO *pInformation;
/*  Points to the DEVICE_PROP structure of current device */
/*  The purpose of this register is to speed up the execution */
DEVICE_PROP *pProperty;

USER_STANDARD_REQUESTS  *pUser_Standard_Requests;
DEVICE_INFO	Device_Info;


void USB_HW_Init()
{

	/**********************************************/
	/* Setup Structures defined by CMSIS Lib      */
	/**********************************************/

	NVIC_InitTypeDef			NVIC_InitStructure;		/* NVIC priority grouping */
	
	/**********************************************/
	/* Enable clocking of the needed peripherials */
	/**********************************************/

	RCC_OTGFSCLKConfig(RCC_OTGFSCLKSource_PLLVCO_Div3);		/* USBCLK = PLLVCO/3 */
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_OTG_FS, ENABLE);	/* enable USB clock */ 
	
	
	/**************************************************/
	/* Configure the Nested Interrupt Controller      */
	/**************************************************/
	
	NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);
	
	
	/**************************************************/
	/* Configure USB							      */
	/**************************************************/

	pInformation = &Device_Info;
	pInformation->ControlState = 2;
	pProperty = &Device_Property;
	pUser_Standard_Requests = &User_Standard_Requests;
	/* Initialize devices one by one */
	pProperty->Init();
	
}

